ssc install revrs
ssc install wyoung
set more off

use "/Users/jrthornton/Library/CloudStorage/Dropbox/Papers/Pronoun Study/TESS Bolsen Deliverables (Data + Codebook)/TESS Bolsen Data.dta" , clear

svyset [pw = WEIGHT] // panel weight


********************************************************************************
*                               Variable coding                                *
********************************************************************************
* Experimental condition variable
gen condition = P_BOLSEN
label define conditionlabel 1 "Control" 2 "Descriptive" 3 "Injunctive" 4 "Both"  , replace
label values condition conditionlabel  
tab condition , gen(c) // for wyoung command which cannot handle factor variables

********************
* Outcome varibles *
********************
gen comfort = B1 if B1<98 // 98 is missing 

gen onlineForm = B2 if B2<98

gen statePronouns = B3 if B3<98

gen transPrej_work = B4 if B4<98
gen transPrej_immoral = B5 if B5<98
revrs transPrej_work , replace
gen transPrej = (transPrej_immoral+transPrej_work)/2
alpha transPrej_immoral transPrej_work
corr transPrej_immoral transPrej_work
spearman transPrej_immoral transPrej_work
*************************
* Conditioning varibles *
*************************

* Party
gen party = PartyID5 if PartyID5 > -1
recode party (1=1) (2=1) (3=2) (4=0) (5=0) 
label define partylabel 0 "Republican" 1 "Democrat" 2 "Independent"  , replace
label values party partylabel  

* Ideology
gen ideology = IDEO if IDEO>-1
recode ideology (1=1) (2=1) (3=2) (4=0) (5=0)
label define ideologylabel 0 "Conservative" 1 "Liberal" 2 "Moderate"  , replace
label values ideology ideologylabel  

* Gender
gen female = GENDER - 1
label define femalelabel 0 "Male" 1 "Female"   , replace
label values female femalelabel  

* Race, four category
gen race = RACE
recode race (1=1) (2=2) (3=4) (4=3) (5=4) (6=4)
label define racelabel 1 "White" 2 "Black" 3 "Latino" 4 "Other"   , replace
label values race racelabel  

********************************************************************************
*                              Primary analyses                                *
********************************************************************************

* Descriptive statistics by party for control group for Figure 1
svy: mean comfort if condition == 1 , over(party)
svy: mean onlineForm if condition == 1 , over(party)
svy: mean statePronouns if condition == 1 , over(party) 
svy: mean transPrej if condition == 1 , over(party) 

* Main effects
svy: reg comfort i.condition
svy: reg statePronouns i.condition
svy: reg onlineForm i.condition
svy: reg transPrej i.condition


* Effects by party
svy: reg comfort i.condition if party==2 // Independent
svy: reg comfort i.condition  if party==0	// Republican
svy: reg comfort i.condition if party==1 // Democrat

svy: reg statePronouns i.condition if party==2 // Independent 
svy: reg statePronouns i.condition if party==0	// Republican
svy: reg statePronouns i.condition if party==1	// Democrat


svy: reg onlineForm i.condition if party==2 // Independent
svy: reg onlineForm i.condition if party==0	// Republican
svy: reg onlineForm i.condition if party==1	// Democrat

svy: reg transPrej i.condition if party==2 // Independent
svy: reg transPrej i.condition if party==0	// Republican
svy: reg transPrej i.condition if party==1	// Democrat

* Extension: effects by sex and party
svy: reg comfort i.condition if female==1 & party==0 //  Republican Women
svy: reg comfort i.condition if female==0  & party==0 // Republican Men
svy: reg comfort i.condition if female==1  & party==1 //  Democratic Women
svy: reg comfort i.condition if female==0  & party==1 //  Democratic Men
svy: reg comfort i.condition if female==1  & party==2 //  Independent Women
svy: reg comfort i.condition if female==0  & party==2 // Independent Men

svy: reg statePronouns i.condition if female==1 & party==0 //  Republican Women
svy: reg statePronouns i.condition if female==0  & party==0 // Republican Men
svy: reg statePronouns i.condition if female==1  & party==1 //  Democratic Women
svy: reg statePronouns i.condition if female==0  & party==1 //  Democratic Men
svy: reg statePronouns i.condition if female==1  & party==2 //  Independent Women
svy: reg statePronouns i.condition if female==0  & party==2 // Independent Men


svy: reg onlineForm i.condition if female==1 & party==0 //  Republican Women
svy: reg onlineForm i.condition if female==1  & party==1 //  Democratic Women
svy: reg onlineForm i.condition if female==0  & party==0 // Republican Men
svy: reg onlineForm i.condition if female==0  & party==1 //  Democratic Men
svy: reg onlineForm i.condition if female==1  & party==2 //  Independent Women
svy: reg onlineForm i.condition if female==0  & party==2 // Independent Men

svy: reg transPrej i.condition if female==1 & party==0 //  Republican Women
svy: reg transPrej i.condition if female==1  & party==1 //  Democratic Women
svy: reg transPrej i.condition if female==0  & party==0 // Republican Men
svy: reg transPrej i.condition if female==0  & party==1 //  Democratic Men
svy: reg transPrej i.condition if female==1  & party==2 //  Independent Women
svy: reg transPrej i.condition if female==0  & party==2 // Independent Men


********************************************************************************
*                              Robusenss checks                                *
********************************************************************************

* Effects by ideological identification 
svy: reg comfort i.condition
svy: reg comfort i.condition if ideology==2 // Moderate
svy: reg comfort i.condition  if ideology==0	// Conservative
svy: reg comfort i.condition  if ideology==1	// Liberal

svy: reg statePronouns i.condition
svy: reg statePronouns i.condition if ideology==2 // Moderate
svy: reg statePronouns i.condition  if ideology==0	// Conservative
svy: reg statePronouns i.condition  if ideology==1	// Liberal

svy: reg onlineForm i.condition
svy: reg onlineForm i.condition if ideology==2 // Moderate
svy: reg onlineForm i.condition  if ideology==0	// Conservative
svy: reg onlineForm i.condition  if ideology==1	// Liberal

svy: reg transPrej i.condition
svy: reg transPrej i.condition if ideology==2 // Moderate
svy: reg transPrej i.condition  if ideology==0	// Conservative
svy: reg transPrej i.condition  if ideology==1	// Liberal

* Multiple comparisons of main analysis
# delimit ;
wyoung comfort statePronouns onlineForm transPrej , 
	cmd(reg OUTCOMEVAR c2 c3 c4, r ) 
	familyp(c2 c3 c4) 
	bootstraps(1000) 
	seed(123)
	;
# delimit cr

* Main analyses with controls
replace PartyID7 = . if PartyID7<0
replace IDEO = . if IDEO<0

svy: reg comfort ATTEND PartyID7 IDEO GENDER AGE i.race EDUC5 INCOME ///
	i.METRO i.condition
svy: reg statePronouns ATTEND PartyID7 IDEO GENDER AGE i.race EDUC5 INCOME ///
	i.METRO i.condition
svy: reg onlineForm ATTEND PartyID7 IDEO GENDER AGE i.race EDUC5 INCOME ///
	i.METRO i.condition
svy: reg transPrej ATTEND PartyID7 IDEO GENDER AGE i.race EDUC5 INCOME ///
	i.METRO i.condition

